package cn.lingyangwl.agile.msg.push.api.constatnts;

import cn.lingyangwl.agile.model.enums.ConfigKeyEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 这里引用配置 {@link ConfigKeyEnum} 的原因是, 一个渠道类型肯定对应多个厂商, 比如短信渠道分别有阿里云短信, 腾讯云短信等等
 * 在推送的时候肯定要选择一种厂商进行推送的, 但是这个选择还是动态的(用户自行在控制台配置), 所以为了应对这种场景, 引入了 {@link ConfigKeyEnum}
 * @author shenguangyang
 */
@Getter
@AllArgsConstructor
public enum ChannelCodeEnum {
    SMS_ALIYUN("阿里云短信",  "sms_aliyun", ChannelTypeEnum.SMS, ConfigKeyEnum.SMS_ALIYUN),
    SMS_TENCENT("腾讯短信",  "sms_tencent", ChannelTypeEnum.SMS, ConfigKeyEnum.SMS_TENCENT),
    SMS_JUMEI("聚美智数短信",  "sms_jumei", ChannelTypeEnum.SMS, ConfigKeyEnum.SMS_JUMEI),

    WX_MINI_APP("微信小程序", "wx_ma", ChannelTypeEnum.WX_MINI_APP, ConfigKeyEnum.WX_MA),
    WX_MP("微信公众号", "wx_mp", ChannelTypeEnum.WX_MP, ConfigKeyEnum.WX_MP),

    EMAIL_TENCENT("腾讯邮箱", "email_tencent", ChannelTypeEnum.EMAIL, ConfigKeyEnum.EMAIL_TENCENT),
    EMAIL_163("网易邮箱", "email_163", ChannelTypeEnum.EMAIL, ConfigKeyEnum.EMAIL_163),

    PC("PC端推送", "pc", ChannelTypeEnum.PC, ConfigKeyEnum.PUSH_SYSTEM_PC),
    ;
    private final String name;

    /**
     * 渠道编码
     */

    private final String code;
    /**
     * 渠道类型
     */
    private final ChannelTypeEnum type;

    /**
     * 使用的配置key, 在初始化渠道客户端会使用指定的配置key
     *
     * {@link ConfigKeyEnum}
     */
    private final ConfigKeyEnum bindConfig;


    public static ChannelCodeEnum ofByBindConfig(String configKey) {
        return Arrays.stream(ChannelCodeEnum.values()).filter(e -> e.getBindConfig().getKey().equalsIgnoreCase(configKey))
                .findFirst().orElse(null);
    }

    public static ChannelCodeEnum ofByCode(String code) {
        return Arrays.stream(ChannelCodeEnum.values()).filter(e -> e.getCode().equalsIgnoreCase(code))
                .findFirst().orElse(null);
    }
}
